﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Input;
using Microsoft.Xna.Framework.Graphics;
using UtilityLibrary;

namespace MapLibrary
{
    public class EditorHullPoint : ITransformable
    {
        private const int SIZE = 50;
        private Vector2 point;
        private EditorConvexHull parent;

        public Vector2 Point
        {
            get { return point; }
        }

        public EditorHullPoint(Vector2 vert, EditorConvexHull parent)
        {
            point = vert;
            this.parent = parent;
        }

        public void EditorDraw(SpriteBatch batch, WorldViewport viewport)
        {
            PrimitiveBrush.RenderPoint(
                batch, 
                viewport.WorldToViewportCoords(point));
        }

        public void EditorDraw(SpriteBatch batch, WorldViewport viewport, Color col)
        {
            PrimitiveBrush.RenderPoint(
                batch,
                viewport.WorldToViewportCoords(point),
                col);
        }

        public bool HasHover(GameInput input, WorldViewport viewport)
        {
            Rectangle rect = GetTransformedRectangle(viewport);

            return input.IsMouseInRectangle(rect, 0.0f);
        }

        private Rectangle GetTransformedRectangle(WorldViewport viewport)
        {
            Rectangle rect;
            Vector2 transformedPoint;

            transformedPoint = viewport.WorldToViewportCoords(point);
            rect.X = (int)(transformedPoint.X - (SIZE / 2));
            rect.Y = (int)(transformedPoint.Y - (SIZE / 2));
            rect.Width = SIZE;
            rect.Height = SIZE;

            return rect;
        }

        public void SetPosition(Vector2 Position)
        {
            point.X = Position.X;
            point.Y = Position.Y;

            parent.ResetToHull();
        }

        public Vector2 GetPosition()
        {
            return point;
        }

        public void SetRotation(float rotation)
        {
            return;
        }

        public float GetRotation()
        {
            return 0.0f;
        }

        public void SetScale(Vector2 newScale)
        {
            return;
        }

        public Vector2 GetScale()
        {
            return Vector2.UnitX + Vector2.UnitY;
        }

        public Vector2 GetCenter()
        {
            return point;
        }

        public bool IsActive()
        {
            return true;
        }
    }
}
